import traceback

from gglib import logger
from gglib.middleware import process_packet
from gglib.packet import PacketRejected
from gglib.utils import import_attr


def handle(session, packet):
    try:
        process_packet(session, packet, incoming=True)
    except PacketRejected:
        return
    # 导入handlers包下面相应模块的handle函数，
    command = packet['command']
    handler = import_attr("gglib.handlers." + command + ".handle")
    handler(session, packet)
